package com.tc.erp.dao;

import java.io.Serializable;
import java.util.List;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;

/**
 * Generic DAO (Data Access Object) with common methods to CRUD POJOs.
 * 
 * @author Peter.Shang@locisoftware.com
 * @date Apr 21, 2008
 * 
 * @param <T>
 * @param <ID>
 */
public interface GenericDao<T, ID extends Serializable> {
	/**
	 * Generic method used to get all objects of a particular type. This is the
	 * same as lookup up all rows in a table.
	 * 
	 * @return List of populated objects
	 */
	List<T> loadAll();

	/**
	 * Generic method to get an object based on class and identifier.
	 * 
	 * @param id
	 *            the identifier (primary key) of the object to get
	 * @return a populated object
	 * 
	 */
	T get(ID id);

	/**
	 * 
	 * @param id
	 * @return
	 */
	T load(ID id);

	/**
	 * Checks for existence of an object of type T using the id arg.
	 * 
	 * @param id
	 *            the id of the entity
	 * @return - true if it exists, false if it doesn't
	 */
	boolean exists(ID id);

	/**
	 * Generic method to save an object - handles both update and insert.
	 * 
	 * @param object
	 *            the object to save
	 * @return the persisted object
	 */
	T save(T object);
	
	T update(T entity);

	/**
	 * Generic method to delete an object based on class and id
	 * 
	 * @param id the identifier (primary key) of the object to remove
	 */
	void delete(ID id);

	/**
	 * 
	 * @param exampleInstance
	 * @param excludeProperty
	 * @return
	 */
	List<T> findByExample(T exampleInstance, String... excludeProperty);

	
	List<T> findByCriteria(Criterion... criterion);
	/**
	 * Flush all pending saves, updates and deletes to the database.
	 */
	void flush();

	/**
	 * Remove all objects from the org.hibernate.Session cache, and cancel all
	 * pending saves, updates and deletes
	 */
	void clear();	
}
